/*
 * This file (RxPixelize.java) is protected by the GNU GPL licence (v2). 
 * Please read the license.txt attached for further informations. 
 * 
 */

package alkwarel.filters;

import alkwarel.objects.AkArtspace;
import alkwarel.objects.AkFilter;
import artx.parameters.AxIntParameter;
import artx.utils.AxLog;

/**
 * @author Xavier Gouchet
 *
 */
public class RxPixelize extends AkFilter {

	/**
	 * Standard Constructor
	 */
	public RxPixelize() {
		super(4010, "pixelize",new String[]{"pixelize size","int"});
	}

	/**
	 * @see alkwarel.objects.AkFilter#Apply(alkwarel.objects.AkArtspace)
	 */
	public boolean Apply(AkArtspace a) {
		
		AxIntParameter pxlSize = null;
		try{
			pxlSize = (AxIntParameter) a.GetParameterManager().GetElement("pixelize size");
		}catch (ClassCastException e){
			AxLog.Debug("AkBlur::Apply =>> can't cast parameter \"pixelize size\" to int");
		}
		int w = 10;
		int h = 10;
		
		if (pxlSize != null){
			w = pxlSize.GetValue();
			h = pxlSize.GetValue();
		}
		for (int x=0; x<(a.width/w); x++){
			for (int y=0; y<(a.height/h); y++){  
				for (int i=0; i<w; i++){
					for (int j=0; j<h; j++){
						a.set((w*x) + i, (h*y) + j, a.get(w*x, h*y));
					}
				}
			}
		}
		return true;
	}

}
